<template>
  <!-- 合作协议登记表 -->
  <div class="app-container">
    <div style="width: 90%; margin-left: 5%;">
      <el-form :inline="true" size="mini" :model="EditObj" style="margin-top: 10px;" label-width="150px" label-position="right"
        class="demo-form-inline">
        <!-- <div style="width: 100%; ">
          <div style="width: 50%; float: left; ">
            <el-form-item label="创建人" style="width: 100%; display: flex;">
              <el-input placeholder="" :disabled="true"></el-input>
            </el-form-item>
          </div>
          <div style="width: 50%; float: left; ">
            <el-form-item label="创建时间" style=" width: 100%; display: flex;">
              <el-input placeholder="" :disabled="true"></el-input>
            </el-form-item>
          </div>

        </div> -->

        <div style="width: 100%; ">
          <div style="width: 50%; float: left; ">
              <el-form-item label="状态" style=" width: 100%; display: flex;">
                <el-select v-model="EditObj.Status" placeholder="请选择状态" style="width: 100%; display: flex;">
                  <el-option v-for="item in StatusOption" :key="item.value" :label="item.label" :value="item.value">
                    <span style="float: left">{{ item.label }}</span>
                  </el-option>
                </el-select>
              </el-form-item>
            </div>
            <div style="width: 50%; float: left; ">
              <el-form-item label="单位" style="width: 100%; display: flex;">
                <el-select v-model="EditObj.Organizeid" clearable placeholder="单位" @change="selectOrid" style="width: 100%; display: flex;">
                  <el-option v-for="item in OrganizeList" :key="item.Organizeid" :label="item.Organizename" :value="item.Organizeid">
                  </el-option>
                </el-select>
              </el-form-item>
            </div>
          </div>
          <div style="width: 100%; ">
            <div style="width: 50%; float: left; ">
              <el-form-item label="输送机构" style="width: 100%; display: flex;">
                <el-select v-model="EditObj.Conveyingmechanism" clearable placeholder="机构" @change="getBatch" style="width: 100%; display: flex;">
                  <el-option v-for="item in Conveyingmechanismlist" :key="item.Conveyingmechanism" :label="item.Conveyingmechanism"
                    :value="item.Conveyingmechanism">
                  </el-option>
                </el-select>
              </el-form-item>
            </div>
            <div style="width: 50%; float: left; ">
              <el-form-item label="批次" style="width: 100%; display: flex;">
                <el-select v-model="EditObj.Batch" clearable placeholder="批次" @change="selectChange" style="width: 100%; display: flex;">
                  <el-option v-for="item in Batchlist" :key="item.Batch" :label="item.Batch" :value="item.Batch">
                    <span style="float: left">{{ item.Batch }}</span>
                    <span style="float: right; color: #8492a6; font-size: 13px">{{ item.Conveyingmechanism }}</span>
                  </el-option>
                </el-select>
              </el-form-item>
            </div>
          </div>
          <br />
          <div style="width: 100%; ">
            <div style="width: 100%; float: left; ">
              <el-form-item label="人数" style=" width: 100%; display: flex;">
                <el-input v-model="EditObj.NumberOfEmployees" placeholder="入单位人数"></el-input>
              </el-form-item>
            </div>

          </div>
          <div style="width: 100%;">
            <div style="width: 50%; float: left; ">
              <el-form-item label="输送日期(起始)" style="width: 100%; display: flex;">
                <el-date-picker v-model="EditObj.StratConveyorDate" type="date" placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
            </div>
            <div style="width: 50%; float: left; ">
              <el-form-item label="输送日期(结束)" style="width: 100%; display: flex;">
                <el-date-picker v-model="EditObj.EndConveyorDate" type="date" placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
            </div>
          </div>
        <div style="width: 100%;">
          <div style="width: 33%; float: left;">
            <el-form-item label="合同证件(双方盖章)">
              <v-Getupload :url="'/Common/UploadFile'" :rno="2222" :bill="EditObj.CooperationAgreementNO"></v-Getupload>
            </el-form-item>
          </div>
          <div style="width: 33%;float: left;">
            <el-form-item label="营业执照/事业单位法人证书/组织机构代码证">
              <v-Getupload :url="'/Common/UploadFile'" :rno="2223" :bill="EditObj.CooperationAgreementNO"></v-Getupload>
            </el-form-item>
          </div>
          <div style="width: 33%;float: left;">
            <el-form-item label="代开发票委托书/其他证件">
              <v-Getupload :rno="2224" :bill="EditObj.CooperationAgreementNO"></v-Getupload>
            </el-form-item>
          </div>
        </div><br />
        <div style="width: 100%;">
          <el-form-item label="备注" style="width: 100%; display: flex;">
            <el-input type="textarea" v-model="EditObj.Remark1" placeholder=""></el-input>
          </el-form-item>
        </div>
      </el-form>
      <el-button type="primary" @click="confirmData" style="width: 100%; ">提交</el-button>
    </div>
  </div>

</template>

<script>
  import path from "path";
  import {
    deepClone
  } from "@/utils";
  import {
    getResidentList,
    updateCooperation
  } from '@/api/resident'
  import {
    getSelectList,
    getConveyingmechanism
  } from '@/api/getSelect'
  import vGetupload from "../Common/Getupload";
  const defaultObject = {

  }
  export default {
    components: {
      vGetupload
    },
    data() {
      return {
        StatusOption: [{
          value: 0,
          label: '发布'
        }, {
          value: 1,
          label: '作废'
        }],
        EditObj: Object.assign({}, defaultObject),
        projectName: "",
        FormDatas: "",
        OrganizeList: [],
        uploadFiles: [], //上传的文件列表
        Conveyingmechanismlist: [],
        Batchlist: [],
        Search: { // 查询条件
          total: 0, // 总记录数
          RNO: '001', // 表编号  根据Controller中对应的表编号
          jsWhere: '' // 自定义条件
        },
        SearchApproval: { // 查部门
          total: 0, // 总记录数
          pageSize: 100, // 一页显示的记录数
          RNO: '002', // 表编号  根据Controller中对应的表编号
          jsWhere: '' // 自定义条件
        },
        SearchSelect: { // 查询条件
          total: 0, // 总记录数
          RNO: '001', // 表编号  根据Controller中对应的表编号
          jsWhere: '' // 自定义条件
        },
        SearchCoo: {
          total: 0, // 总记录数
          RNO: '003', // 表编号  根据Controller中对应的表编号
          jsWhere: '' // 自定义条件
        }
      }
    },
    computed: {
      //文件的上传路径
      //附带用户id和项目名称

    },
    created() {
      this.getSelect()
      if (this.$route.query.JumpID != undefined) {
      	this.DataListData()
      }
    },
    methods: {
      async DataListData() {
        this.SearchCoo.CooperationAgreementNO = this.$route.query.JumpID
        const resCoo = await getResidentList({
          data: JSON.stringify(this.SearchCoo)
        })
        this.EditObj = deepClone(resCoo.data.Table[0])
      },
      async getSelect() { // 获取下拉
        const res = await getConveyingmechanism({
          billID: 2
        })
        this.Conveyingmechanismlist = res.data.Table
        const res2 = await getSelectList({
          data: JSON.stringify(this.SearchApproval)
        })
        this.OrganizeList = res2.data.Table
      },
      //获取批次
      async getBatch() {
        this.SearchSelect.Conveyingmechanism = this.EditObj.Conveyingmechanism
        const resbatch = await getSelectList({
          data: JSON.stringify(this.SearchSelect)
        })
        this.Batchlist = resbatch.data.Table

      },
      //选择批次后 信息对接
      selectChange(val) {
        let obj = {};
        obj = this.Batchlist.find((item) => {
          return item.Batch === val;
        });
        this.NumberOfEmployees = obj.NumberOfEmployees
        this.EditObj.StratConveyorDate = obj.StratConveyorDate
        this.EditObj.EndConveyorDate = obj.EndConveyorDate
      },
      //选择公司
      selectOrid(val) {
        let obj = {};
        obj = this.OrganizeList.find((item) => {
          return item.Organizeid === val;
        });
        this.EditObj.Organizename = obj.Organizename
      },
      async confirmData() {

        /* const result =getupload(this.FormDatas) */
        this.EditObj.DeliverType = 2
        const result = await updateCooperation({
          billID: this.EditObj.CooperationAgreementNO,
          head: JSON.stringify(this.EditObj),
          IsPostBack: true
        })
        if (result.code === 20000) {
          const {
            description,
            key,
            name
          } = this.EditObj
          this.dialogVisible = false
          this.$notify({
            title: 'Success',
            dangerouslyUseHTMLString: true,
            message: result.message,
            type: 'success'
          })

          this.$router.push({
            path: '/CooperationAgreementDetailE'
          })
        } else {
          this.$notify({
            title: 'error',
            dangerouslyUseHTMLString: true,
            message: result.message,
            type: 'error'
          })
        }
      }

      //文件上传失败时的钩子

    }
  }
</script>

<style>
  .el-form-item__content {
    flex: 1;
  }
</style>
